package com.cardbaobao.cardbabyclient.widget;

import android.content.Context;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cardbaobao.cardbabyclient.R;


/**
 * Description: 设置支付密码
 * Created by FHW
 * on 2017/9/21
 */

public class CustomPhoneCodeView extends LinearLayout {

    //添加布局必不可少的工具
    private LayoutInflater mInflater;

    private View mView;
    private ImageView iv_icon1, iv_icon2, iv_icon3, iv_icon4, iv_icon5, iv_icon6;
    private TextView tv_text1, tv_text2, tv_text3, tv_text4, tv_text5, tv_text6;

    public CustomPhoneCodeView(Context context) {
        this(context, null);
    }

    public CustomPhoneCodeView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomPhoneCodeView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        if (mView == null) {
            //初始化
            mInflater = LayoutInflater.from(getContext());
            //添加布局文件
            mView = mInflater.inflate(R.layout.custom_phone_code_view, null);

            tv_text1 = (TextView) mView.findViewById(R.id.tv_text1);
            tv_text2 = (TextView) mView.findViewById(R.id.tv_text2);
            tv_text3 = (TextView) mView.findViewById(R.id.tv_text3);
            tv_text4 = (TextView) mView.findViewById(R.id.tv_text4);
            tv_text5 = (TextView) mView.findViewById(R.id.tv_text5);
            tv_text6 = (TextView) mView.findViewById(R.id.tv_text6);

            iv_icon1 = (ImageView) mView.findViewById(R.id.iv_icon1);
            iv_icon2 = (ImageView) mView.findViewById(R.id.iv_icon2);
            iv_icon3 = (ImageView) mView.findViewById(R.id.iv_icon3);
            iv_icon4 = (ImageView) mView.findViewById(R.id.iv_icon4);
            iv_icon5 = (ImageView) mView.findViewById(R.id.iv_icon5);
            iv_icon6 = (ImageView) mView.findViewById(R.id.iv_icon6);

            //然后使用LayoutParams把控件添加到子view中
            Toolbar.LayoutParams lp = new Toolbar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL);
            addView(mView, lp);
        }
    }

    public void setShowNum(int num, char[] str) {
        tv_text1.setText("");
        tv_text2.setText("");
        tv_text3.setText("");
        tv_text4.setText("");
        tv_text5.setText("");
        tv_text6.setText("");
        iv_icon1.setBackgroundResource(R.color.color_DDDDDD);
        iv_icon2.setBackgroundResource(R.color.color_DDDDDD);
        iv_icon3.setBackgroundResource(R.color.color_DDDDDD);
        iv_icon4.setBackgroundResource(R.color.color_DDDDDD);
        iv_icon5.setBackgroundResource(R.color.color_DDDDDD);
        iv_icon6.setBackgroundResource(R.color.color_DDDDDD);
        switch (num) {
            case 1:
                tv_text1.setText(str[0] + "");
                iv_icon1.setBackgroundResource(R.color.color_FFAB18);
                break;
            case 2:
                tv_text1.setText(str[0]+ "");
                tv_text2.setText(str[1]+ "");
                iv_icon1.setBackgroundResource(R.color.color_FFAB18);
                iv_icon2.setBackgroundResource(R.color.color_FFAB18);
                break;
            case 3:
                tv_text1.setText(str[0]+ "");
                tv_text2.setText(str[1]+ "");
                tv_text3.setText(str[2]+ "");
                iv_icon1.setBackgroundResource(R.color.color_FFAB18);
                iv_icon2.setBackgroundResource(R.color.color_FFAB18);
                iv_icon3.setBackgroundResource(R.color.color_FFAB18);
                break;
            case 4:
                tv_text1.setText(str[0]+ "");
                tv_text2.setText(str[1]+ "");
                tv_text3.setText(str[2]+ "");
                tv_text4.setText(str[3]+ "");
                iv_icon1.setBackgroundResource(R.color.color_FFAB18);
                iv_icon2.setBackgroundResource(R.color.color_FFAB18);
                iv_icon3.setBackgroundResource(R.color.color_FFAB18);
                iv_icon4.setBackgroundResource(R.color.color_FFAB18);
                break;
            case 5:
                tv_text1.setText(str[0]+ "");
                tv_text2.setText(str[1]+ "");
                tv_text3.setText(str[2]+ "");
                tv_text4.setText(str[3]+ "");
                tv_text5.setText(str[4]+ "");
                iv_icon1.setBackgroundResource(R.color.color_FFAB18);
                iv_icon2.setBackgroundResource(R.color.color_FFAB18);
                iv_icon3.setBackgroundResource(R.color.color_FFAB18);
                iv_icon4.setBackgroundResource(R.color.color_FFAB18);
                iv_icon5.setBackgroundResource(R.color.color_FFAB18);
                break;
            case 6:
                tv_text1.setText(str[0]+ "");
                tv_text2.setText(str[1]+ "");
                tv_text3.setText(str[2]+ "");
                tv_text4.setText(str[3]+ "");
                tv_text5.setText(str[4]+ "");
                tv_text6.setText(str[5]+ "");
                iv_icon1.setBackgroundResource(R.color.color_FFAB18);
                iv_icon2.setBackgroundResource(R.color.color_FFAB18);
                iv_icon3.setBackgroundResource(R.color.color_FFAB18);
                iv_icon4.setBackgroundResource(R.color.color_FFAB18);
                iv_icon5.setBackgroundResource(R.color.color_FFAB18);
                iv_icon6.setBackgroundResource(R.color.color_FFAB18);
                break;
        }
    }

}
